﻿using LanguagePolish.Controls.Meta;
using LanguagePolish.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using LanguagePolish.EntityModel;

namespace LanguagePolish.Views
{
    /// <summary>
    /// Логика взаимодействия для CalendarView.xaml
    /// </summary>
    public partial class CalendarView : UserControl
    {
        CalendarViewModel vm;

        public CalendarView()
        {
            InitializeComponent();
            Teacher teacher = LinksProvider.Model.CurrentUser.Teacher;
            if (LinksProvider.Model.IsSeeAll || teacher == null)
                calendar.LessonsProvider = AllLessonsProvider.Instance;
            else
                calendar.LessonsProvider = new TeacherLessonsProvider(teacher);
            vm = new CalendarViewModel();
            DataContext = vm;
            calendar.AddLesson += calendar_AddLesson;
            calendar.EditLesson += calendar_EditLesson;
            calendar.RemoveLesson += calendar_RemoveLesson;
        }

        void calendar_AddLesson(object sender, Controls.AddLessonEventArgs e)
        {
            vm.AddLesson(e.Date);
            calendar.Reload();
        }

        void calendar_EditLesson(object sender, Controls.EditLessonEventArgs e)
        {
            vm.EditLesson(e.Lesson);
            calendar.Reload();
        }

        void calendar_RemoveLesson(object sender, Controls.RemoveLessonEventArgs e)
        {
            vm.RemoveLesson(e.Lesson);
            calendar.Reload();
        }
        
    }
}
